// instanceof 原理 用代码演示

export function myInstance(instance: any, origin: any): boolean {
  if(instance == null) return false;

  const type = typeof instance;
  if(type !== 'object' && type !== 'function') { // 值类型没有原型链
    return false;
  }

  let tempInstance = instance // 防止修改instance
  while(tempInstance) {
    if(tempInstance.__proto__ === origin.prototype) {
      return true;// 配上了
    }

    tempInstance = tempInstance.__proto__; // 顺着原型链往上找
  }

  return false;
}


console.log(myInstance({}, Object))